﻿using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class IPTypeManager
    {
        /// <summary>
        /// 获取所有IP地址信息
        /// </summary>
        /// <returns></returns>
        public List<IPType> GetAllIPType()
        {
            return new DAL.IPTypeService().GetAllIPType();
        }
        /// <summary>
        /// 获取所有IP地址信息
        /// </summary>
        /// <returns></returns>
        public List<IPType> GetAllIPType(string ipType)
        {
            return new DAL.IPTypeService().GetAllIPType(ipType);
        }
        public List<IPType> GetGetAllIPType1()
        {
            List<IPType> list = new List<IPType>();
            list = GetAllIPType("view_AGVIPType"); //先获取AGV的
            list.AddRange(GetAllIPType("view_RemoteIPType")); //获取远程IO的并全部加载在一起
            return list;
        }
        /// <summary>
        /// 根据IP地址获取该IP类型
        /// </summary>
        /// <param name="ip">IP地址</param>
        /// <param name="list">所有IP地址的集合</param>
        /// <returns>IP地址类型 1：AGV 2：远程IO 0：其他</returns>
        public int GetIPTypeByIP(string ip,List<IPType> list)
        {
            List<IPType> objList = new List<IPType>();
            objList = list.FindAll(s=>s.IPAddress==ip);
            if (objList.Count != 0)
                return list.Find(s => s.IPAddress == ip).IPId;
            else return 0;
        }       
    }
}
